package pl.edu.agh.student.janikhankus.earley;

import java.util.ArrayList;

/**
 * Class representing parse tree. In parse tree every MyTree object is an node.
 * @author tom
 *
 */
public class MyTree {
	String name;
	ArrayList<MyTree> childer = null;
	public double prob; 
	
	public MyTree(String name, double prob){
		this.name = name;
		this.prob = prob;
	}
	
	@Override
	public String toString(){
		return name;
	}
	
	/**
	 * Deletes children list, set new node name and set probability to 1
	 * @param name New node name
	 */
	public void reset(String name){
		this.name = name;
		childer = null;
		prob = 1; 
	}
	
	/**
	 * Adds new child to nodes children list
	 * @param child New child/node
	 */
	public void addChild(MyTree child){
		if(childer == null){
			childer = new ArrayList<MyTree>();
		}
		childer.add(child);
	}
	
	/**
	 * Returns i-th child
	 * @param i Child number
	 * @return i-th child
	 */
	public MyTree getChild(int i){
		return childer.get(i);
	}
	
	public int size(){
		if(childer == null){
			return 0;
		}
		return childer.size();
	}
	
	public ArrayList<MyTree> getChilder(){
		return childer;
	}
	
}
